<template>
  <div>

    <!--卡片视图-->
    <el-card class="box-card">
      <el-row>
        <el-form :model="searchForm" label-width="70px">
          <el-col :span="5">
            <el-form-item label="用户名">
              <el-input v-model="searchForm.gname"  size="small"></el-input>
            </el-form-item>
          </el-col>


        </el-form>
        <el-button type="info" plain @click="searchList">搜索</el-button>
      </el-row>

      <el-table
        :data="GoodsList"
        stripe
        style="width: 100%">
        <el-table-column
          prop="gname"
          label="商品名称"
          width="180">
        </el-table-column>
        <el-table-column
          prop="price"
          label="价格"
          width="180">
        </el-table-column>
        <el-table-column
          prop="gbrand"
          label="店铺">
        </el-table-column>
        <el-table-column
          label="库存">
          <template slot-scope="scope">
            {{scope.row.gnum}}
          </template>
        </el-table-column>

        <el-table-column
          label="上架时间"
          prop="hiredate">
          <template slot-scope="scope">
            {{scope.row.ctime | dateFit('YYYY/MM/DD')}}
          </template>
        </el-table-column>

        <el-table-column
          fixed="right"
          label="操作">
          <template slot-scope="scope">
            <el-button @click="getGoods(scope.row.id)" size="small" type="text"  :disabled="displayks(scope.row.gnum)">购买
            </el-button>

          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pagenum"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="page.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>


    </el-card>
  </div>
</template>

<script>
    export default {
        name: "List",
      data(){
          return{
            disbuy:false,
            searchForm:{},
            GoodsList:[],
            page:{
              pagenum:0,
              pagesize:5
            },
            total:0
          }
      },
      methods:{
          searchList:function () {
            this.$http.post("goods/list/"+this.page.pagenum+"/"+this.page.pagesize,this.searchForm).then((res)=>{
              this.GoodsList=res.data.result.list;
              this.total=res.data.result.total;
            })
          },
        handleCurrentChange:function(val){

          this.page.pagenum=val;
          this.searchList();
        },
        handleSizeChange:function (val) {
          this.page.pagesize=val;
          this.searchList();
        },
        displayks:function (gnum) {
            debugger;
          if(gnum>0){
            return false;
          }else{
            return true;
          }
        },
        getGoods:function (id) {

          this.$router.push("/addGoods?id="+id);
        }
      },
      mounted() {
          this.searchList();
      }
    }
</script>

<style scoped>

</style>
